package com.chain.BrotherExchange.wxapi;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.chain.BrotherExchange.App;
import com.chain.BrotherExchange.utils.Androids;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;

public class WXEntryActivity extends Activity implements IWXAPIEventHandler {

    /**
     * 登录
     */
    private static final int RETURN_MSG_TYPE_LOGIN = 1;

    /**
     * 分享
     */
    private static final int RETURN_MSG_TYPE_SHARE = 2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        App.getInstance().mWxApi.handleIntent(getIntent(), this);
    }

    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp resp) {
        switch (resp.getType()) {
            case RETURN_MSG_TYPE_LOGIN:
                //weChatLogin(resp);
                break;
            case RETURN_MSG_TYPE_SHARE:
                weChatShare(resp);
                break;
        }

        finish();
    }

    /**
     * 微信分享
     */
    private void weChatShare(BaseResp resp) {
        switch (resp.errCode){
            case BaseResp.ErrCode.ERR_OK:
                Androids.makeText("分享成功");
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                Androids.makeText("分享取消");
                break;

            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                Androids.makeText("分享失败");
                break;
        }
    }

}
